package com.zf.openfeign.caller.feign.fallback;

import com.zf.openfeign.caller.entity.FileUploadEntity;
import com.zf.openfeign.caller.entity.UserInfo;
import com.zf.openfeign.caller.feign.BaseFeignClient;
import feign.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 降级回调，发生超时或者其他异常时，进入降级回调。
 * 开启降级配置后才会进入降级回调
 */
@Slf4j
@Component
public class BaseFeignClientFallbackFactory implements FallbackFactory<BaseFeignClient> {
    @Override
    public BaseFeignClient create(Throwable cause) {
        return new BaseFeignClient() {
            @Override
            public String hello(String username) {
                log.info("回调 hello fallback: ", cause);
                return "";
            }

            @Override
            public String hello2(String username, MultiValueMap<String, String> hdMap, String oneHdxx) {
                log.info("回调 hello2 fallback: ", cause);
                return "";
            }

            @Override
            public UserInfo getUserInfo(String name, Integer age) {
                log.info("回调 getUserInfo fallback: ", cause);
                return null;
            }

            @Override
            public UserInfo getUserInfo2(UserInfo userInfo) {
                log.info("回调 getUserInfo2 fallback: ", cause);
                return null;
            }

            @Override
            public UserInfo getPathVar(String username, Integer age) {
                log.info("回调 getPathVar fallback: ", cause);
                return null;
            }

            @Override
            public UserInfo addUserInfo(UserInfo userInfo) {
                log.info("回调 addUserInfo fallback: ", cause);
                return null;
            }

            @Override
            public UserInfo uploadFile(String username, Integer age, List<MultipartFile> fileList) {
                log.info("回调 uploadFile fallback: ", cause);
                return null;
            }

            @Override
            public UserInfo uploadFile2(FileUploadEntity fileUploadEntity) {
                log.info("回调 uploadFile2 fallback: ", cause);
                return null;
            }

            @Override
            public Response downloadFile() {
                log.info("回调 downloadFile fallback: ", cause);
                return null;
            }
        };
    }
}
